% This file provides a \begin{maple}...\end{maple} environment.  The
% environment is similar to \begin{verbatim}...\end{verbatim} in
% effect.  However there are several important differences.
%
% First of all, the spacing is quite different with respect to the
% surrounding environment.  This environment attempts not to introduce
% vertical white space at the beginning and end.
%
% Secondly the font is \small \tt.
%
% Thirdly the environment is indented.  The amount of the indentation
% can be set with the command  \setlength{\mapleindent}{...}.
%
% Finally this environment formats its contents line by line,
% attempting to cause breaks to occur only at respectable points
% without causing grotesquely underfull/overfull pages.
%
% Written: Fall '89 by david Casperson
% Revised: 21 Jun 1990 by david Casperson to correct a ligature
%   problem in the maple environment discovered by Lee Qiao.
%   Hopefully !` and ?` now print correctly.
% Rewritten: August, 1993, by Urs von Matt, ETH Zuerich

% indent of the left margin with respeect to the surrounding environment
\newlength{\mapleindent}%
\setlength{\mapleindent}{\leftmargin}%

\newif\ifMapleCommandline

\begingroup
  \catcode `|=0
  \catcode `[= 1
  \catcode `]=2
  \catcode `\{=12
  \catcode `\}=12
  \catcode `\\=12
  |gdef|@xmaple#1\end{maple}[#1|end[maple]]%
|endgroup

\def\maple{%
  \list{}{\itemindent 0pt
          \labelwidth 0pt
          \listparindent 0pt
          \leftmargin \mapleindent
          \rightmargin 0pt
          \topsep \smallskipamount
          \parsep \parskip}%
  \item[]\if@minipage\else\vskip\parskip\fi
  %
  \leftskip \@totalleftmargin
  \rightskip \z@
  \parindent \z@
  \parfillskip \@flushglue
  \parskip \z@
  \def\par{%
    %
    \@ifnextchar{>}%
      {\ifMapleCommandline
         \nopagebreak\@@par
       \else
         \pagebreak[2]\@@par
         \MapleCommandlinetrue
       \fi
       \baselineskip = \normalbaselineskip
       \lineskiplimit = \normallineskiplimit}%
      {\ifMapleCommandline
         \nopagebreak\@@par
         \MapleCommandlinefalse
       \else
         \nopagebreak\@@par
         \baselineskip = 0.75\normalbaselineskip
         \lineskiplimit = -\normalbaselineskip
       \fi%
       %
       \@ifnextchar{\maplepar}%
         {\vskip 0.75\normalbaselineskip \pagebreak[2]}%
          % \hrule width \linewidth height 1cm\pagebreak[2]}%
         {\nopagebreak\@@par}%
      }%
  }%  \def\par
  \let\maplepar\par
  \MapleCommandlinetrue
  %
  \obeylines
  %
  \small
  %
  \tt \catcode``=13 \@noligs \let\do\@makeother \dospecials
  \frenchspacing \@vobeyspaces \@xmaple
}%

\def\endmaple{%
  \normalbaselines
  \endlist
}%

